package com.cy.aircompressor.main.ui.dataanalysis.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.Observer;

import com.cy.aircompressor.api.RepositoryImpl;
import com.cy.aircompressor.entity.sensor.Sensor;
import com.cy.aircompressor.entity.sensor.SensorStatisticsData;
import com.drug.lib.util.DLog;
import com.drug.lib.view.recycptr.bean.RowEntity;
import com.net.model.base.Resource;
import com.net.model.viewmodel.BaseViewModel;

import java.security.MessageDigest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 版权：周和权 版权所有
 *
 * @author zhouhequan
 * 版本：1.0
 * 创建日期：2021/11/12 or 23:27
 * 描述：---
 */
public class DataAnalysisViewModel extends BaseViewModel<RepositoryImpl> {
    private MediatorLiveData<Resource<RowEntity<Sensor>>> querySensorByPageObservable;
    private MediatorLiveData<Resource<List<SensorStatisticsData>>> querySensorStatisticsDataDataObservable;

    public DataAnalysisViewModel(@NonNull Application application) {
        super(application);
        bindBaseModel(RepositoryImpl.get());
        querySensorByPageObservable = new MediatorLiveData<>();
        querySensorStatisticsDataDataObservable = new MediatorLiveData<>();
    }


    public void querySensorByPage(String compressorId) {
        querySensorByPageObservable.addSource(baseModel.querySensorByPage(1,100, compressorId, null, null, null, null), new Observer<Resource<RowEntity<Sensor>>>() {
            @Override
            public void onChanged(Resource<RowEntity<Sensor>> rowEntityResource) {
                querySensorByPageObservable.setValue(rowEntityResource);
            }
        });
    }

    public void querySensorStatisticsData(String startTime, String endTime, String sn, Integer type) {
        querySensorStatisticsDataDataObservable.addSource(baseModel.querySensorStatisticsData(startTime, endTime, "asc", sn, type), new Observer<Resource<List<SensorStatisticsData>>>() {
            @Override
            public void onChanged(Resource<List<SensorStatisticsData>> authBeanResource) {
                querySensorStatisticsDataDataObservable.setValue(authBeanResource);
            }
        });
    }

    public MediatorLiveData<Resource<RowEntity<Sensor>>> getQuerySensorByPageObservable() {
        return querySensorByPageObservable;
    }

    public MediatorLiveData<Resource<List<SensorStatisticsData>>> getQuerySensorStatisticsDataDataObservable() {
        return querySensorStatisticsDataDataObservable;
    }
}
